package com.hgy.carsb.entity;

import lombok.Data;

import java.math.BigDecimal;

@Data
public class UnitRatioDetail {
    private String thisMonth;
    private String lastMonth;
    private String subMonth;
    private String monthRate;
    private String thisYear;
    private String lastYear;
    private String subYear;
    private String yearRate;

    public UnitRatioDetail(){}

    public UnitRatioDetail(String thisMonth, String lastMonth, String thisYear, String lastYear) {
        set(thisMonth, lastMonth, thisYear, lastYear);
    }
    public UnitRatioDetail(IndicatorDetail indicatorDetail){
        set(indicatorDetail.getThisMonth(), indicatorDetail.getLastMonth(), indicatorDetail.getThisYear(), indicatorDetail.getLastYear());
    }

    private void set(String thisMonth, String lastMonth, String thisYear, String lastYear){
            this.thisMonth = thisMonth;
            this.lastMonth = lastMonth;
            this.thisYear = thisYear;
            this.lastYear = lastYear;
            this.subMonth = new BigDecimal(thisMonth).subtract(new BigDecimal(lastMonth)).toString();
            this.subYear = new BigDecimal(thisYear).subtract(new BigDecimal(lastYear)).toString();
            if (lastMonth.equals("0")){
                this.monthRate = "0";
            }else {
                this.monthRate = new BigDecimal(this.subMonth).multiply(new BigDecimal(100)).divide(new BigDecimal(lastMonth), 2, BigDecimal.ROUND_HALF_UP).toString();
            }
            if (lastYear.equals("0")){
                this.yearRate = "0";
            }else {
                this.yearRate = new BigDecimal(this.subYear).multiply(new BigDecimal(100)).divide(new BigDecimal(lastYear), 2, BigDecimal.ROUND_HALF_UP).toString();
            }
    }
}
